#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建菜单栏
    //QMenuBar* menuBar = new QMenuBar();
    //可以避免内存泄漏进一步规范程序
    QMenuBar* menuBar = this->menuBar();
    this->setMenuBar(menuBar);

    QMenu* menu = new QMenu("文件");
    menuBar->addMenu(menu);

    QAction* action1 = new QAction("新建");
    QAction* action2 = new QAction("打开");
    menu->addAction(action1);
    menu->addSeparator();
    menu->addAction(action2);

    //设置图标
    action1->setIcon(QIcon(":/fitness"));
    action2->setIcon(QIcon(":/programmer"));
    //注：如果当前的QMenu被设置在了ManuBar上面的话，此时文本就会被图标覆盖
    //而子菜单就不会了
    menu->setIcon(QIcon(":/programmer"));
}

MainWindow::~MainWindow()
{
    delete ui;
}

